<?php

namespace App\Jobs;

use App\Models\ActiveCode;
use Hashids\Hashids;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class CreateActiveCode implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * @var ActiveCode
     */
    private $active_code;

    /**
     * Create a new job instance.
     *
     * @param ActiveCode $activeCode
     */
    public function __construct(ActiveCode $activeCode)
    {
        $this->active_code = $activeCode;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $this->active_code->code = (new Hashids('',6, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'))->encode( $this->active_code->id + 100000);
        $this->active_code->save();
    }
}
